package me.ingxin.android.tools.app.drawer

import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import me.ingxin.android.tools.app.databinding.ItemDrawerPageBinding

/**
 * Created on 2022/05/26
 */
class DrawerPageAdapter : RecyclerView.Adapter<DrawerPageAdapter.ViewHolder>() {

    /**修改成自己的数据类型*/
    val datas = ArrayList<String>()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(
            ItemDrawerPageBinding.inflate(
                LayoutInflater.from(parent.context),
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.bind(datas[position])
    }

    override fun getItemCount(): Int = datas.size

    class ViewHolder(private val binding: ItemDrawerPageBinding) :
        RecyclerView.ViewHolder(binding.root) {

        private lateinit var item: String

        init {
            binding.tv.setOnClickListener {
                Toast.makeText(it.context, "点击$item", Toast.LENGTH_SHORT).show()
            }
        }


        fun bind(item: String) {
            this.item = item
            binding.tv.text = item
        }

    }

}